<?php
namespace Amis\dataviewer;

use Amis\Basics\AmisBasics;

class Carousel extends AmisBasics
{
    public string $type = 'carousel';

    /**
     * 外层 Dom 的类名
     * @param string $className
     * @return $this
     */
    public function className(string $className = 'panel-default')
    {
        $this->className = $className;
        return $this;
    }

    public function options(CarouselOptions $options)
    {
        $this->options = $options;
        return $this;
    }

    /**
     * 自定义schema来展示数据
     * @param array $itemSchema
     * @return $this
     */
    public function itemSchema(array $itemSchema)
    {
        $this->itemSchema = $itemSchema;
        return $this;
    }

    /**
     * 是否自动轮播
     * @param bool $auto
     * @return $this
     */
    public function auto(bool $auto = true)
    {
        $this->auto = $auto;
        return $this;
    }

    /**
     * 切换动画间隔 单位秒
     * @param int $interval
     * @return $this
     */
    public function interval(int $interval = 5)
    {
        $this->interval = $interval . 's';
        return $this;
    }

    /**
     * 切换动画时长 单位秒
     * @param float $duration
     * @return $this
     */
    public function duration(float $duration = 0.5)
    {
        $this->duration = round($duration, 1) . 's';
        return $this;
    }

    /**
     * 宽度
     * @param string $width
     * @return $this
     */
    public function width(string $width = 'auto')
    {
        $this->width = $width;
        return $this;
    }

    /**
     * 高度
     * @param string $height
     * @return $this
     */
    public function height(string $height = '200px')
    {
        $this->height = $height;
        return $this;
    }

    /**
     * 显示左右箭头、底部圆点索引
     * @param array|string[] $controls
     * @return $this
     */
    public function controls(array $controls = ['dots', 'arrows'])
    {
        $this->controls = $controls;
        return $this;
    }

    /**
     * 左右箭头、底部圆点索引颜色，默认light，另有dark模式
     * @param bool $isLight
     * @return $this
     */
    public function controlsTheme(bool $isLight = true)
    {
        $this->controlsTheme = $isLight ? 'light' : 'dark';
        return $this;
    }

    /**
     * 切换动画效果，默认fade，另有slide模式
     * @param bool $isFade
     * @return $this
     */
    public function animation(bool $isFade = true)
    {
        $this->animation = $isFade ? 'fade' : 'slide';
        return $this;
    }

    /**
     * 图片默认缩放模式 "cover" | "contain"
     * @param bool $isCover
     * @return $this
     */
    public function thumbMode(bool $isCover = true)
    {
        $this->thumbMode = $isCover ? 'cover' : 'contain';
        return $this;
    }
}